package org.anyin.gitee.cloud.center.auth.extension.impl;

import lombok.extern.slf4j.Slf4j;
import org.anyin.gitee.cloud.center.auth.enums.LoginTypeEnum;
import org.anyin.gitee.cloud.center.auth.extension.LoginHandler;
import org.anyin.gitee.cloud.center.auth.extension.dto.LoginUserDTO;
import org.anyin.gitee.cloud.center.upms.api.SysUserFeignApi;
import org.anyin.gitee.cloud.center.upms.api.resp.SysUserResp;
import org.anyin.gitee.cloud.lib.core.web.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class EmailLoginHandler implements LoginHandler {

    @Autowired
    private SysUserFeignApi sysUserFeignApi;

    @Override
    public LoginUserDTO login(String... content) {
        String email = content[0];
        String password = content[1];
        SysUserResp sysUser = sysUserFeignApi.infoByEmail(email).getData();
        sysUser.setPassword(null);

        LoginUserDTO user = new LoginUserDTO();
        user.setSysUser(sysUser);
        return user;
    }

    @Override
    public LoginTypeEnum extension() {
        return LoginTypeEnum.EMAIL;
    }
}
